/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function validateLoginForm(form, action) {
    var isValid = true;
    var formValues = form.getValues();

    // intial check for validity
    if(!form.isValid()) {
        isValid = false;
    }

    if(!isValid)
        signUpFormMask.hide();
    return isValid;

}

function validateForgotForm(form, action) {
    var isValid = true;
    var formValues = form.getValues();

    // intial check for validity
    if(!form.isValid()) {
        isValid = false;
    }
    
    if(!isValid)
        signUpFormMask.hide();
    return isValid;

}

function validateSignUpForm(form, action) {
    var isValid = true;
    var formValues = form.getValues();

    // intial check for validity
    if(!form.isValid()) {
        isValid = false;
    }

    // Check domain to see if its test.com
    if(formValues.signUpEmail.length > 0) {
        var index = formValues.signUpEmail.indexOf('@');
        if(formValues.signUpEmail.substring(index+1) == 'test.com') {
            isValid = false
            form.markInvalid([{id:'signUpEmailTextField', msg:'test.com is an invalid domain'}])
        }
    }

    // check to see if emails are the same
    if(formValues.signUpEmail != formValues.reEmail) {
        isValid = false;
        form.markInvalid([{id:'reEmailTextField', msg:'These fields need to match'}])
    }

    if(formValues.signUpPassword != formValues.rePassword) {
        isValid = false;
        form.markInvalid([{id:'rePasswordTextField', msg:'These fields need to match'}])
    }

    if(!formValues.readAgreement) {
        isValid = false
        form.markInvalid([{id: 'signUpAgreementTextField', msg:'You must read terms and agree'}])
    }

    if(!isValid)
        signUpFormMask.hide();
    return isValid;

}
